<?php
	class Bahasa_model extends Model{
		function Bahasa_model(){
			parent::Model();
		}
        
        function list_data($nip="",$where="", $order="", $ro=false) { 
            
        	if ($nip=="") {
        		return "";
        	} else {
                $this->db->where(array('nip' => $nip));
                $this->db->or_where(array('nip_baru' => $nip));
        	}
        	
            if ($where!='') {
                $this->db->where($where);
            }
            if ($order == "") {
                $this->db->order_by('nip asc');
                $this->db->order_by('nip_baru asc');
            } else {
                $this->db->order_by($order);
            }
            $this->db->from('pegawai');
            $q = $this->db->get();

            $s = "
              <table id=\"scrollable\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"tbl\">
                <thead>
                  <tr>
                    <th>No</th>
                    <th>Bahasa</th>
                    <th>Kemampuan</th>
                    <th>Jenis Bahasa</th>
                    ";
            if ($ro==false) {
                $s .= " <th colspan='2'> Aksi </th>";
            }
            $s .= "</tr></thead><tbody>";
			$i = 1;

            $this->load->model('Datum_model');
            foreach($q->result() as $row) {
                if ($i % 2 == 1) {
                    $kelas = "event2";
                } else {
                    $kelas = "event";
                }
                
                $this->db->where(array('id_pegawai' => $row->idspg_pegawai));                
                $q1 = $this->db->get('bahasa');
                if ($q1->num_rows() > 0) {
                	foreach ($q1->result() as $row1) {
		               
		                
		                $s .= "
                        
		              <tr class=\"$kelas\" id=\"row-".$row1->id_bahasa."\" >
		                <td><div align=\"right\">$i.&nbsp;&nbsp;&nbsp;</div></td>
		                <td>".$row1->bahasa."</td>
		                <td>".$row1->kemampuan."</td>
		                <td>".$row1->jenis_bahasa."</td>
                        ";
		                if ($ro==false) {
		                    $s .= "
		                    <td><div align='center'> <a href='".base_url()."index.php/bahasa/form_edit/".$row1->id_bahasa."' title=\"Ubah Data\" class=\"edit\"><img src='".base_url()."images/edit.gif' border='0'></a></div></td>";
                           // if($this->input->post('page'))  
		                    $s .= "<td><div align='center'><a href=\"javascript:deleteRow(".$row1->id_bahasa.")\"><img src='".base_url()."images/del.gif' border='0'></a></div></td>";
		                }
		                $s .= "
		              </tr>";
		
		                $i++;
                	} //foreach
                } else {
                	continue;
                }

            }
            $s .= "</tbody></table>";
            return $s;
        }

        function entry_data($form_id, $form_action, $arr=array()) {
            
            
            $ret = "
            <form id=\"".$form_id."\" action=\"".$form_action."\" method=\"post\">
            <fieldset >
            <table class=\"formTabel\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"1\">
              <tr>
                <td class=\"kolom\" valign=\"top\">NIP</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"nip\" id=\"nip\" value=\"".(isset($arr['nip'])?$arr['nip']:$this->session->userdata('nip'))."\" /></td>
              </tr>  
              <tr>
                <td class=\"kolom\" valign=\"top\">Nama</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"text\" name=\"data[bahasa]\" size=\"50\" value=\"".(isset($arr['bahasa'])?$arr['bahasa']:"")."\" /></td>
              </tr>
              
              <tr>
                <td class=\"kolom\" valign=\"top\">Kemampuan</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"radio\" name=\"data[kemampuan]\"  value=\"Aktif\" ".(isset($arr['kemampuan'])?$arr['kemampuan'] == 'Aktif'?'checked="checked"':"":"")." /> Aktif
                <input type=\"radio\" name=\"data[kemampuan]\"  value=\"Pasif\" ".(isset($arr['kemampuan'])?$arr['kemampuan'] == 'Pasif'?'checked="checked"':"":"")." /> Pasif</td>
              </tr>
              
         
              <tr>
                <td class=\"kolom\" valign=\"top\">Jenis Bahasa</td>
                <td valign=\"top\">:</td>
                <td valign=\"top\"><input type=\"radio\" name=\"data[jenis_bahasa]\"  value=\"Daerah\" ".(isset($arr['jenis_bahasa'] )?$arr['jenis_bahasa'] == 'Daerah'?'checked="checked"':"":"")." /> Daerah 
                <input type=\"radio\" name=\"data[jenis_bahasa]\"  value=\"Nasional\" ".(isset($arr['jenis_bahasa'])? $arr['jenis_bahasa'] == 'Nasional'?'checked="checked"':"":"")." /> Nasional
                <input type=\"radio\" name=\"data[jenis_bahasa]\"  value=\"Internasional\" ".(isset($arr['jenis_bahasa'])? $arr['jenis_bahasa'] == 'Internasional'?'checked="checked"':"":"")." /> Internasional 
                </td>
              </tr>
             
              <tr>
                <td valign=\"top\">&nbsp;</td>
                <td valign=\"top\">&nbsp;</td>
                <td valign=\"top\">
                  <input class=\"tombol\" type=\"button\" name=\"btn_kembali\" id=\"btn_kembali\" value=\"<< Kembali\" />
                  <input class=\"tombol\" type=\"submit\" name=\"button\" id=\"button\" value=\"   Simpan   \" />
                </td>
              </tr>
            </table>
            </fieldset>
            </form>
              ";
            
            return $ret;
        }

        function simpan($arr, $is_update=false, $id='') {
            if (!$is_update) {
                $this->db->insert('bahasa', $arr);
                
            } else {
                $this->db->where('id_bahasa', $id);
                $this->db->update('bahasa', $arr);
            }
        }
        
	}
?>